package cn.wolfcode.car.business.web.controller.business;


import cn.wolfcode.car.base.domain.User;
import cn.wolfcode.car.base.service.IUserService;
import cn.wolfcode.car.business.domain.BusServiceItem;
import cn.wolfcode.car.business.query.BusServiceItemQuery;
import cn.wolfcode.car.business.service.IBusServiceItemService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.List;

/**
 * 岗位控制器
 */
@Controller
@RequestMapping("business/busServiceItem")
public class BusServiceItemController {
    //模板前缀
    private static final String prefix = "business/system/busServiceItem/";

    @Autowired
    private IBusServiceItemService busServiceItemService;
    @Autowired
    private IUserService userService;

    //页面------------------------------------------------------------
    //列表
    @RequiresPermissions("system:busServiceItem:view")
    @RequestMapping("/listPage")
    public String listPage(){
        return prefix + "list";
    }

    @RequiresPermissions("system:busServiceItem:add")
    @RequestMapping("/addPage")
    public String addPage(){
        return prefix + "add";
    }
    //数据-----------------------------------------------------------
    //列表
    @RequiresPermissions("system:post:list")
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<BusServiceItem> query(BusServiceItemQuery qo){
        TablePageInfo<BusServiceItem> info = busServiceItemService.query(qo);
        return info;
    }

    @RequiresPermissions("system:busServiceItem:edit")
    @RequestMapping("/editPage")
    public String editPage(Long id, Model model){
        model.addAttribute("busServiceItem", busServiceItemService.get(id));
        return prefix + "edit";
    }

    //新增
    @RequiresPermissions("system:busServiceItem:add")
    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusServiceItem busServiceItem){
        BusServiceItem busServiceItem1=busServiceItem;
        busServiceItemService.save(busServiceItem);
        return AjaxResult.success();
    }

    //编辑
    @RequiresPermissions("system:busServiceItem:edit")
    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(BusServiceItem busServiceItem){
        busServiceItemService.update(busServiceItem);
        return AjaxResult.success();
    }

    //删除
    @RequiresPermissions("system:busServiceItem:remove")
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        busServiceItemService.deleteBatch(ids);
        return AjaxResult.success();
    }
    //上架
    @RequestMapping("/saleOn")
    @ResponseBody
    public AjaxResult saleOn(Long id){
        busServiceItemService.saleOn(id);
        return AjaxResult.success();
    }
    //下架
    @RequestMapping("/saleOff")
    @ResponseBody
    public AjaxResult saleOff(Long id){
        busServiceItemService.saleOff(id);
        return AjaxResult.success();
    }
    @RequestMapping("/auditPage")
    public String auditPage(Model model,Long id){
        BusServiceItem busServiceItem = busServiceItemService.get(id);
        model.addAttribute("busServiceItem",busServiceItem);
        List<User> shopOwner = userService.queryByRoleKey("shopOwner");
        model.addAttribute("shopOwners",shopOwner);
        if (busServiceItem.getDiscountPrice().compareTo(new BigDecimal(3000))>0){
            //套餐价格比3000大
            List<User> financial = userService.queryByRoleKey("financial");
            model.addAttribute("financials",financial);
        }
        return prefix+"audit";
    }
    @RequestMapping("/audit")
    @ResponseBody
    public AjaxResult audit(Long id,Long shopOwnerId,Long financialId,String info){
        busServiceItemService.startAudit(id,shopOwnerId,financialId,info);
        return AjaxResult.success();
    }
}
